package cmq.socket;

import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.SocketChannel;
import java.nio.charset.StandardCharsets;

/**
 * @ProjectName: interview
 * @Package: cmq.socket
 * @ClassName: NIOClient
 * @Author: chenmengqi
 * @Description:
 * @Date: 2020/2/18 11:23 下午
 * @Version: 1.0
 */
public class NIOClient {
    public static void main(String[] args) {
        ByteBuffer allocate = ByteBuffer.allocate(1024);

        try {
            SocketChannel channel = SocketChannel.open();
            channel.connect(new InetSocketAddress("127.0.0.1", 3000));


            channel.write(StandardCharsets.UTF_8.encode("测试1"));
            channel.write(StandardCharsets.UTF_8.encode("测试2"));
            channel.write(StandardCharsets.UTF_8.encode("测试3"));
            channel.write(StandardCharsets.UTF_8.encode("测试4"));
            channel.write(StandardCharsets.UTF_8.encode("测试5"));
            channel.write(StandardCharsets.UTF_8.encode("测试6"));
            channel.write(StandardCharsets.UTF_8.encode("测试7"));
            channel.write(StandardCharsets.UTF_8.encode("测试8"));


//            System.out.println("写入数据量" + write);

            channel.close();

        } catch (Exception e) {
            e.printStackTrace();
        }

    }
}
